package com.example.assistant;


import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 加载物模型定义
 */

public class DeviceModelLoader {
    private static final Map<String, JsonNode> deviceSchemas = new HashMap<>();

    static {
        try {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode rootNode = mapper.readTree(new File("src/main/resources/device_knowledge.json"));

            for (JsonNode node : rootNode) {
                String deviceType = node.get("device_type").asText();
                deviceSchemas.put(deviceType, node.get("schema"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static JsonNode getSchema(String deviceType) {
        return deviceSchemas.get(deviceType);
    }
}